﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;


namespace UnionPay4WP
{
    public class OrderClass
    {
        public OrderClass(){
         AppName = "UPNoCard";
         Version = "1.01";
         MerchantSummary = "1234567890abcdef1234567890abcdef12345678";
         ResultUri = "";
         TransCurrency = "156";
         SubmitTime = "";
         Type = "";
         OrderId = "";
         MerchantName = "";
         Signature = "";
         ServiceInfo = "";
         SpId = "";
         SysProvide = "";
         TerminalId = "";
         //TransAmount = 0;
         TransAmountStr = "";
         MerchantId = "";
         MerchantCountry = "156";
         OrderContent = "";
         UseTestMode = false;
         ContentProvide = "";
         UserProvide = "";

         //SubmitTime_dt;

        /*以下两个常量 用来表示订单是否有效*/
         VALID = true;
        INVALID = false;

        

         AccountNumber2 = "";
         LimitedAmount = "";
        
        }

        /*以下字段是需要传过来的*/
        internal string AppName = "UPNoCard";
        internal string Version = "1.01";
        internal string MerchantSummary = "1234567890abcdef1234567890abcdef12345678";
        internal string ResultUri = "";
        internal string TransCurrency = "156";
        internal string SubmitTime = "";
        internal string Type = "";
        internal string OrderId = "";
        internal string MerchantName = "";
        internal string Signature = "";
        internal string ServiceInfo = "";
        internal string SpId = "";
        internal string SysProvide = "";
        internal string TerminalId = "";
        internal int TransAmount { get; set; }
        internal string TransAmountStr = "";
        internal string MerchantId = "";
        internal string MerchantCountry = "156";
        internal string OrderContent = "";
        internal bool UseTestMode = false;
        internal string ContentProvide = "";
        internal string UserProvide = "";

        internal DateTime SubmitTime_dt;

        /*以下两个常量 用来表示订单是否有效*/
        internal static bool VALID = true;
        internal static bool INVALID = false;

       /*以下五个变量是向服务器提交的字段，暂存在这里*/ 
        internal  string SessionID;
        internal static byte[] KeyDes3;
        internal static string pin;
        internal static string date;
        internal string AccountNumber2 = "";
        internal static string LimitedAmount = "";
       
        /*以下函数用来验证订单是否有效，即订单字段是否完全*/
        public bool isValid()
        {
            if ("UPNoCard" != AppName)
                return INVALID;
            if ("1.01" != Version)
                return INVALID;
            if ("" == OrderId || OrderId.Length > 64 || !StringPlus.IsAllNumber(OrderId)) 
                return INVALID;
            if (256 != Signature.Length || !StringPlus.IsAllHex(Signature))
                return INVALID;
            if (4 != SpId.Length || !StringPlus.IsAllNumber(SpId))
                return INVALID;
            if (8 != SysProvide.Length || !StringPlus.IsAllNumber(SysProvide)) 
                return INVALID;
            if ("" == OrderContent || OrderContent.Length > 128)
                return INVALID;
            return VALID;
        }
    }
}
